<?php
    /*
     * @Author: KingMin 
     * @Date: 2022-3-12 11:42:04
     * @Last Modified by:   KingMin 
     * @Last Modified time: 2022-3-12 11:42:09
     * @The authors website: https://www.kingmin.cn  
    */
    $pagesRoot=substr(str_replace('\\','/',dirname(__FILE__)),0,stripos(str_replace('\\','/',dirname(__FILE__)),'/GatewayWorker'));
    @require_once $pagesRoot.'/include/init.php';
    use \GatewayWorker\Lib\Gateway;
    use \Workerman\Lib\Timer;
    class chat{
        public function chatMarkRead($dt){
            // $newDt=[
            //     "receiverId"=>$dt['data']['receiverId'],
            //     "senderId"=>$dt['data']['senderId'],
            // ];
            if(@$dt['data']['senderId']){
                if(isUserOnLine($dt['data']['senderId'],false,"chatDetail_")){
                    $rt=Chat_Model::chatMarkRead($dt['data']['receiverId'],$dt['data']['senderId']);
                    echo $rt;
                }
            }
        }
        public function chatConnect($dt){
           @$uid=$dt['uid'];
           if(!$uid){
               return false;
           }
           $tkFix="chatDetail_";
           if(!RedisService::op()){
                RedisService::init(3);//tonken  用户信息 uid_*
            }
            $bclogintm=3600*3;
            RedisService::setToken($tkFix.$uid);
            $hcuser=RedisService::getUser();
            if($hcuser){
                RedisService::delUser($tkFix.$uid);
                RedisService::setUser($hcuser,$bclogintm);
                return $hcuser;
            }else{
                $user=[
                    "uid"=>$uid,
                    "formType"=>$dt['formType']??"",
                    "token"=>$dt['token']??"",
                    "time"=>date("Y-m-d H:i:s"),
                ];
                RedisService::setUser($user,$bclogintm);
                return $user;
            }
        }
        public function chatOut($dt){
           @$uid=$dt['uid'];
           if(!$uid){
               return false;
           }
           $tkFix="chatDetail_";
           if(!RedisService::op()){
                RedisService::init(3);//tonken  用户信息 uid_*
            }
            $bclogintm=3600*3;
            RedisService::setToken($tkFix.$uid);
            RedisService::delUser($tkFix.$uid);
            return false;
        }
        
    }
?>